package com.suredy.app.porject.model.sp;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;

import org.springframework.format.annotation.DateTimeFormat;

import com.suredy.core.model.BaseModel;

/**
 * 费用、资金
 * 
 * @author VIVID.G
 * @since 2015-10-22
 * @version v0.1
 */
@MappedSuperclass
public class Money extends BaseModel {

	private static final long serialVersionUID = 1L;

	/* 费用支出？ */
	@Column(name = "pay_out", nullable = false, columnDefinition = "int default 1")
	private Boolean payOut;

	/* 对应支出时：是否已经收回资金。null=不需要收回，true=已经收回，false=未收回 */
	/* 对应收入时：是否已经归还资金。null=不需要归还，true=已经归还，false=未归还 */
	@Column(name = "gave_back", columnDefinition = "int default null")
	private Boolean gaveBack;

	/* 资金回收时间 */
	@Column(name = "back_time")
	@DateTimeFormat(pattern = "yyyy-MM-dd")
	private Date backTime;

	/* 是否到账 */
	@Column(name = "in_account", nullable = false, columnDefinition = "int default 1")
	private Boolean inAccount;

	/* 资金数量 */
	@Column(nullable = false, columnDefinition = "double(255,2) default 0.00")
	private Double total;

	/* 资金时间 */
	@Column(nullable = false)
	@DateTimeFormat(pattern = "yyyy-MM-dd")
	private Date time;

	/* 资金名目 */
	@Column(length = 300)
	private String name;

	/* 资金来源（单位/人） */
	@Column(length = 300)
	private String source;

	/* 是否开发票 */
	@Column(columnDefinition = "int default 1")
	private Boolean invoice;

	/* 发票开局情况说明 */
	@Column(name = "invoice_des", length = 3000)
	private String invoiceDes;

	/* 发票金额 */
	@Column(nullable = true, columnDefinition = "double(255,2)")
	private Double invoiceTotal;

	/* 备注 */
	@Column(length = 3000)
	private String remark;

	/* 财务确认标识 */
	@Column(name = "cw_confirm", columnDefinition = "int default null")
	private Boolean cwConfirm;

	public Boolean getPayOut() {
		return payOut;
	}

	public void setPayOut(Boolean payOut) {
		this.payOut = payOut;
	}

	public Boolean getGaveBack() {
		return gaveBack;
	}

	public void setGaveBack(Boolean gaveBack) {
		this.gaveBack = gaveBack;
	}

	public Date getBackTime() {
		return backTime;
	}

	public void setBackTime(Date backTime) {
		this.backTime = backTime;
	}

	public Boolean getInAccount() {
		return inAccount;
	}

	public void setInAccount(Boolean inAccount) {
		this.inAccount = inAccount;
	}

	public Double getTotal() {
		return total;
	}

	public void setTotal(Double total) {
		this.total = total;
	}

	public Date getTime() {
		return time;
	}

	public void setTime(Date time) {
		this.time = time;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getSource() {
		return source;
	}

	public void setSource(String source) {
		this.source = source;
	}

	public Boolean getInvoice() {
		return invoice;
	}

	public void setInvoice(Boolean invoice) {
		this.invoice = invoice;
	}

	public String getInvoiceDes() {
		return invoiceDes;
	}

	public void setInvoiceDes(String invoiceDes) {
		this.invoiceDes = invoiceDes;
	}

	public Double getInvoiceTotal() {
		return invoiceTotal;
	}

	public void setInvoiceTotal(Double invoiceTotal) {
		this.invoiceTotal = invoiceTotal;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public Boolean getCwConfirm() {
		return cwConfirm;
	}

	public void setCwConfirm(Boolean cwConfirm) {
		this.cwConfirm = cwConfirm;
	}

	@Transient
	public boolean isOverDate() {
		if (this.getBackTime() == null)
			return true;

		return this.getBackTime().before(new Date());
	}

}
